/*
 * 英才汇硕信息科技有限公司 拥有本软件版权 2021 并保留所有权利。
 * Copyright 2021, YCHS Information&Science Techology Co.,Ltd,
 * All right reserved.
 */
package com.ychs.lawyerback.controller;

import com.ychs.lawyerback.common.R;
import com.ychs.lawyerback.dto.ContractCancellationsQueryDTO;
import com.ychs.lawyerback.dto.ContractQueryDTO;
import com.ychs.lawyerback.pojo.ContractCancellations;
import com.ychs.lawyerback.pojo.ContractEntity;
import com.ychs.lawyerback.service.ContractService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @author mayujing
 * @version 1.0
 */

@RestController
@RequestMapping("/contract")
@Slf4j
public class ContractController {

    @Autowired
    private ContractService contractService;


    @ApiOperation("获取所有合同")
    @GetMapping("/list")
    public R<?> getContractsByCondition(ContractQueryDTO contractQueryDTO) {
        Map<String,Object> result = contractService.getContractsByCondition(contractQueryDTO);
        return R.success(result);
    }

    @ApiOperation("录入新合同")
    @PostMapping("/add")
    public R<?> addContract(@RequestBody ContractEntity contractEntity) {
        int res = contractService.addContract(contractEntity);
        return res > 0 ? R.success() : R.fail();
    }

    @ApiOperation("修改合同")
    @PostMapping("/edit")
    public R<?> editContract(@RequestBody ContractEntity contractEntity) {
        int res = contractService.editContract(contractEntity);
        return res > 0 ? R.success() : R.fail();
    }

    @ApiOperation("注销合同")
    @PostMapping("/delContract")
    public R<?> delContract(@RequestBody ContractEntity contractEntity) {
        int res = contractService.delContract(contractEntity);
        return res > 0 ? R.success() : R.fail();

    }

    @ApiOperation("修改合同状态")
    @PostMapping("/changeContractActive")
    public R<?> changeContractActive(@RequestBody ContractEntity contractEntity) {
        int res = contractService.changeContractActive(contractEntity);
        return res > 0 ? R.success() : R.fail();
    }


    @ApiOperation("获取已经注销的合同")
    @GetMapping("/getCancelContract")
    public R<?> getCancelContract(ContractCancellationsQueryDTO contractCancellationsQueryDTO) {
        Map<String,Object> result = contractService.getCancelContract(contractCancellationsQueryDTO);
        return R.success(result);
    }

    @ApiOperation("重启已注销的合同")
    @GetMapping("/reStart")
    public R<?> reStart(String contractName) {
        log.info("contractName:{}", contractName);
        int res = contractService.reStart(contractName);
        return res > 0 ? R.success() : R.fail();
    }

}
